package com.um.jdy.ykc.command;

import com.um.jdy.ykc.utils.RadixsUtil;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import lombok.Data;

/**
 * 读取实时监测数据（运营平台->充电桩）
 *
 * @author 甘天伟
 * @since 2022/6/27
 * 版权所有 广州优匠科技有限公司
 */
@Data
public class Cmd12ReadRealtimeData extends YkcCommand {

    /**
     * 桩编码：7个字节
     */
    private String code;

    /**
     * 枪号：1个字节
     */
    private int gunNo;

    public Cmd12ReadRealtimeData(int serial, String code, int gunNo) {
        super();

        this.serial = serial;
        this.encFlag = RadixsUtil.hexToInteger("00");
        this.command = RadixsUtil.hexToInteger("12");

        this.code = code;
        this.gunNo = gunNo;

        byte[] _code = RadixsUtil.hexToBytes(code);

        ByteBuf buff = Unpooled.buffer();
        buff.writeBytes(fillZeroBytes(_code, 7 - _code.length));
        buff.writeByte(gunNo);

        this.data = new byte[buff.readableBytes()];
        buff.readBytes(data);
        buff.release();

        postConstruct();
    }
}
